package com.example.springbootdemo.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
    private static final Logger LOGGER = LoggerFactory.getLogger(DateUtil.class);
    private static final String dateType = "yyyy-MM-dd HH:mm:ss";
    private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateType);

    /**
     * yyyy-MM-dd HH:mm:ss 转Date方法
     *
     * @return Date
     */
    public static Date valueOf(String stringDate) {
        Date date = null;
        try {
            date = simpleDateFormat.parse(stringDate);
        } catch (ParseException e) {
            LOGGER.error("Date VALUEOF FIAL,INFO: " + date);
            throw new RuntimeException(e);
        }
        return date;
    }


    public static String valueOf(Date date) {
        return simpleDateFormat.format(date);
    }

    public static String valueOf(long date) {
        return simpleDateFormat.format(new Date(date));
    }

    public static void main(String[] args) {
        long a = 156165456461L;
    }
}
